package au.com.betaversion.csv;

import static org.junit.Assert.assertNotNull;

import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;

import org.apache.commons.io.FileUtils;
import org.junit.Test;

import au.com.bytecode.opencsv.CSVReader;

public class ReadCSV {
	
	@Test
	public void readFromUrl() {
		try {
			File file = new File("temp_download");
			FileUtils.copyURLToFile(new URL("http://casa.gov.au/wcmswr/asp/casadata/register/data/ACRFTREG.CSV"), file);
			assertNotNull(file);
			
			CSVReader csvReader = new CSVReader(new FileReader(file));
			String[] nextLine;
			while( (nextLine = csvReader.readNext()) != null) {
				System.out.println(nextLine[0]);
			}
			
			file.delete();
		} catch (MalformedURLException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}
